/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Conn;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 *
 * @author valentinus
 */
public class Koneksi {
 private static String jdbcURL = "jdbc:Oracle:thin:@localhost:1521:xe";
    private static String user = "apb";
    private static String password = "apb";
    private static Connection connection = null;

    public static Connection getKoneksi() {
        try {
//            DriverManager.registerDriver(new OracleDriver());
//            Class.forName("org.gjt.mm.mysql.Driver");
            connection = DriverManager.getConnection(jdbcURL, user, password);
            System.out.println("koneksi berhasil");
        } catch (Exception ex) {
            System.out.println("message: " + ex.getMessage());
        }
        return connection;
    }

    public boolean isConnected() {

        if (connection != null) {
            return true;
        } else {
            return false;
        }
    }

    public boolean getClosed() {
        if (isConnected()) {
            try {
                connection.close();
                connection = null;
            } catch (SQLException ex) {
                ex.printStackTrace();
            }
            return true;
        } else {
            return false;
        }
    }

    public String getJdbcURL() {
        return jdbcURL;
    }

    public void setJdbcURL(String jdbcURL) {
        this.jdbcURL = jdbcURL;
    }

    public String getUser() {
        return user;
    }

    public void setUser(String user) {
        this.user = user;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Connection getConnection() {
        return connection;
    }

    public void setConn(Connection connection) {
        this.connection = connection;
    }

    public static void main(String[] args) {
        Koneksi konek = new Koneksi();
        konek.getKoneksi();
    }
}
